<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <script>

    (function () {

      // var smallPlaneArr = [1, 2, 234, 24, 343];
      var smallPlaneArr = [{}, {}, {}, {}];


      function getList() {
        // return smallPlaneArr  //不能直接返回数组本身！！

        // 浅拷贝
        // return smallPlaneArr.slice(0, smallPlaneArr.length)
        // 浅拷贝
        // return new Array().concat(smallPlaneArr)
        // 浅拷贝
        // return [...smallPlaneArr]

        let temp = [];
        smallPlaneArr.forEach((el) => {
          let obj = { ...el }
          temp.push(obj);
        });
        return temp;
      }

      function addList(value) {
        smallPlaneArr.push(value)
      }

      function removeList(i) {
        smallPlaneArr.splice(i, 1)
      }
      // 当你要公开的属性很多时，可以把要公开的属性，放在一个对象中。最后公开对象。
      window.plane = { "getPalne": getList, "addPlane": addList, "removePlane": removeList }

    })();

    // let arr = plane.getPalne()
    // console.log(arr);
    // plane.addPlane("aa")
    // arr = plane.getPalne()
    // console.log(arr);

    // 如果数组是对象，

    let arr = plane.getPalne()
    arr[0].x = 100;
    arr[0].y = 50;
    console.log(arr);// [{x:100,y:50},{},{},{}]

    let arr2 = plane.getPalne();
    console.log(arr2); // [{},{},{},{}]

    plane.removePlane(0)
    plane.removePlane(0)
    arr2 = plane.getPalne();
    console.log(arr2); // [{},{}]


  </script>
</body>

</html>